package baidu.com.matedemo.util;

import android.content.Context;
import android.location.LocationManager;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * Created by niufei01 on 2017/9/14.
 */

public class DemoUtils {

    public static String toFormatJson(Object obj) {
        Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
        return gson.toJson(obj);
    }

    /**
     * 检查设置中的"位置"是否已经打开
     */
    public static boolean isLocationEnabled(Context context) {
        LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        boolean isNetworkProviderEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        boolean isGpsProviderEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        if (isNetworkProviderEnabled || isGpsProviderEnabled) {
            return true;
        }
        return false;
    }
}
